package com.doit.day01;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.filter.*;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * 增 put 缓冲
 * 删
 * 改
 * 查询
 */
public class _12_scan数据 {
    public static void main(String[] args) throws IOException {
        Configuration conf = HBaseConfiguration.create();
        //设置参数
        conf.set("hbase.zookeeper.quorum","linux01:2181,linux02:2181,linux03:2181");
        //创建连接对象
        Connection conn = ConnectionFactory.createConnection(conf);
        //获取连接对象
        Admin admin = conn.getAdmin();

        //table对象，这个对象就是用来对于表里面数据的操作
        Table table = conn.getTable(TableName.valueOf("test:teacher"));

        Scan scan = new Scan();
//        scan.withStartRow("rowkey003".getBytes(StandardCharsets.UTF_8));
//        scan.withStopRow("rowkey007".getBytes(StandardCharsets.UTF_8));
        PrefixFilter prefixFilter = new PrefixFilter("rowkey001".getBytes(StandardCharsets.UTF_8));
        ColumnPrefixFilter columnPrefixFilter = new ColumnPrefixFilter("a".getBytes(StandardCharsets.UTF_8));
        FilterList filterList = new FilterList();
        //and的关系
        filterList.addFilter(prefixFilter);
        filterList.addFilter(columnPrefixFilter);




        scan.setFilter(filterList);

        ResultScanner scanner = table.getScanner(scan);
        Iterator<Result> iterator = scanner.iterator();
        while (iterator.hasNext()){
            Result next = iterator.next();
            while (next.advance()){
                Cell current = next.current();
                String family = new String(CellUtil.cloneFamily(current));
                String rowKey = new String(CellUtil.cloneRow(current));
                String qualifier = new String(CellUtil.cloneQualifier(current));
                String value = new String(CellUtil.cloneValue(current));
                System.out.println(rowKey+","+family+","+qualifier+","+value);
            }

        }


    }
}
